package com.pethome.pet.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.pet.domain.PetLost;
import com.pethome.pet.service.IPetLostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 丢失宠物信息Controller
 * 
 * @author ruoyi
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/pet/lost")
@Slf4j
public class PetLostController extends BaseController
{
    @Autowired
    private IPetLostService petLostService;

    /**
     * 顾客发布寻宠启示
     * @param petLost 宠物信息
     * @return
     */
    @PostMapping("/addLostPet")
    public AjaxResult addLostPet(@RequestBody PetLost petLost)
    {
        petLost.setPetLostStatus(1L);
        return toAjax(petLostService.insertPetLost(petLost));
    }

    /**
     * 获取丢失的宠物信息
     * @param status  1-宠物丢失，2-已找到，3-未知
     * @return
     */
    @GetMapping("/getPetListByStatus")
    public TableDataInfo getPetListByStatus(@RequestParam("status") Long status )
    {
        log.warn(" ==========search_petLostBySatus"+status);
        PetLost petLost = new PetLost();
        petLost.setPetLostStatus(status);
        List<PetLost> list = petLostService.selectPetLostList(petLost);
        return getDataTable(list);
    }





    /**
     * 查询丢失宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetLost petLost)
    {
        startPage();
        List<PetLost> list = petLostService.selectPetLostList(petLost);
        return getDataTable(list);
    }

    /**
     * 导出丢失宠物信息列表
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:export')")
    @Log(title = "丢失宠物信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PetLost petLost)
    {
        List<PetLost> list = petLostService.selectPetLostList(petLost);
        ExcelUtil<PetLost> util = new ExcelUtil<PetLost>(PetLost.class);
        util.exportExcel(response, list, "丢失宠物信息数据");
    }

    /**
     * 获取丢失宠物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:query')")
    @GetMapping(value = "/{petLostId}")
    public AjaxResult getInfo(@PathVariable("petLostId") Long petLostId)
    {
        return success(petLostService.selectPetLostByPetLostId(petLostId));
    }

    /**
     * 新增丢失宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:add')")
    @Log(title = "丢失宠物信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetLost petLost)
    {
        return toAjax(petLostService.insertPetLost(petLost));
    }

    /**
     * 修改丢失宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:edit')")
    @Log(title = "丢失宠物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetLost petLost)
    {
        return toAjax(petLostService.updatePetLost(petLost));
    }

    /**
     * 删除丢失宠物信息
     */
    @PreAuthorize("@ss.hasPermi('pet:lost:remove')")
    @Log(title = "丢失宠物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{petLostIds}")
    public AjaxResult remove(@PathVariable Long[] petLostIds)
    {
        return toAjax(petLostService.deletePetLostByPetLostIds(petLostIds));
    }
}
